package com.ybkj.o2o.zhuanche.controller.promote;

import com.alibaba.fastjson.JSON;
import com.ybkj.o2o.zhuanche.amqp.DockingSuperviseApi;
import com.ybkj.o2o.zhuanche.common.AesUtil;
import com.ybkj.o2o.zhuanche.common.DataGrid;
import com.ybkj.o2o.zhuanche.common.api.DaijiaApi;
import com.ybkj.o2o.zhuanche.common.api.PassengerApi;
import com.ybkj.o2o.zhuanche.common.query.Car2Query;
import com.ybkj.o2o.zhuanche.common.query.CarTypeQuery;
import com.ybkj.o2o.zhuanche.common.query.OrderQuery;
import com.ybkj.o2o.zhuanche.controller.v4.Error;
import com.ybkj.o2o.zhuanche.controller.v4.ErrorConstantV4;
import com.ybkj.o2o.zhuanche.controller.v4.ResultTransport;
import com.ybkj.o2o.zhuanche.entity.Car;
import com.ybkj.o2o.zhuanche.entity.CarType;
import com.ybkj.o2o.zhuanche.entity.CarTypeRel;
import com.ybkj.o2o.zhuanche.entity.ChargeStartTime;
import com.ybkj.o2o.zhuanche.entity.Order;
import com.ybkj.o2o.zhuanche.entity.OrderTemp;
import com.ybkj.o2o.zhuanche.entity.Passenger;
import com.ybkj.o2o.zhuanche.entity.ServiceEntity;
import com.ybkj.o2o.zhuanche.manager.CarManager;
import com.ybkj.o2o.zhuanche.manager.CarTypeManager;
import com.ybkj.o2o.zhuanche.manager.OrderManager;
import com.ybkj.o2o.zhuanche.manager.OrderTempManager;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController("ZhuanCheOrderResv4up")
@RequestMapping("api/orders/v4up")
public class ZhuanCheOrderRes {

  @Autowired
  private OrderManager orderManager;

  @Autowired
  private OrderTempManager orderTempManager;

  @Autowired
  private CarTypeManager carTypeManager;

  @Autowired
  private CarManager carManager;

  @Autowired
  private DaijiaApi daijiaApi;
  
  @Autowired
  private PassengerApi passengerApi;

  @Autowired
  @Qualifier("dsRabbitTemplate")
  private RabbitTemplate dsRabbitTemplate;
  
  @Autowired
  private DockingSuperviseApi dockingSuperviseApi;


  /**
   * APP查询车辆类型.
   */

  @ResponseBody
  @RequestMapping(value = "queryCarTypes", method = RequestMethod.GET)
  public ResultTransport queryTypes(@RequestParam("companyId") Long companyId,
      @RequestParam("appKey") String appKey) {
    if (StringUtils.isBlank(appKey) || null == companyId) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      List<Map<String, Object>> list = carTypeManager.queryCarTypes(companyId, appKey);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(list);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 司机端查询专车类型.
   */

  @ResponseBody
  @RequestMapping(value = "queryCarType", method = RequestMethod.GET)
  public ResultTransport queryType(@RequestParam("employId") Long employId,
      @RequestParam("appKey") String appKey) {
    if (StringUtils.isBlank(appKey) || null == employId) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      Car car = carManager.queryByEmployId(employId, appKey);
      if (null == car) {
        return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_HAS_NO_CAR);
      }

      List<Map<String, Object>> map =
          carTypeManager.findByCarTypeIdV4up(car.getCarTypeId(), car.getCompanyId(), appKey);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(map);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 后台查询车辆.
   */
  @ResponseBody
  @RequestMapping(value = "findByTiaoJian", method = RequestMethod.GET)
  public ResultTransport findByTiaoJian(
      @RequestParam(required = false, value = "companyId") Long companyId,
      @RequestParam(required = false, value = "companyName") String companyName, 
      @RequestParam(required = false, value = "carType") String carType,
      @RequestParam(required = false, value = "carNumber") String carNumber,
      @RequestParam(required = false, value = "employName") String employName,
      @RequestParam(required = false, value = "status") String status,
      @RequestParam(required = false, value = "isPlatforms") String isPlatforms,
      @RequestParam(required = false, value = "page") Integer page,
      @RequestParam(required = false, value = "rows") Integer rows,
      @RequestParam(required = false, value = "insurance") Boolean insurance,
      @RequestParam(required = false, value = "overhaul") Boolean overhaul,
      @RequestParam(required = false, value = "rentalCompanyId") Long rentalCompanyId,
      @RequestParam(required = false, value = "rentalCompanyName") String rentalCompanyName,
      @RequestParam("appKey") String appKey) {
    if (StringUtils.isBlank(appKey)) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      Car2Query car2Query = new Car2Query();
      car2Query.setCompanyId(companyId);
      car2Query.setCompanyName(companyName);
      car2Query.setCarType(carType);
      car2Query.setCarNumber(carNumber);
      car2Query.setEmployName(employName);
      car2Query.setStatus(status);
      car2Query.setIsPlatforms(isPlatforms);;
      car2Query.setPage(page);
      car2Query.setRows(rows);
      car2Query.setAppKey(appKey);
      Calendar calendar = Calendar.getInstance();
      calendar.add(Calendar.MONTH, 1);
      if (null  != insurance && insurance) {
        car2Query.setInsurance(calendar.getTime());
      }
      if (null != overhaul && overhaul) {
        car2Query.setOverhaul(calendar.getTime());
      }
      car2Query.setRentalCompanyId(rentalCompanyId);
      car2Query.setRentalCompanyName(rentalCompanyName);
      DataGrid<Car> dataGrid = carManager.findByTiaojians(car2Query);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(dataGrid);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }

  }

  /**
   * 根据车牌号查询车辆.
   */

  @ResponseBody
  @RequestMapping(value = "queryCarByNumber", method = RequestMethod.GET)
  public ResultTransport queryCarByNumber(@RequestParam("carNumber") String carNumber,
      @RequestParam("appKey") String appKey) {
    if (StringUtils.isBlank(appKey) || StringUtils.isBlank(carNumber)) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      Car car = carManager.queryCarByNumber(carNumber, appKey);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(car);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  
  }
  
  /**
   * 根据车牌号和班次查询车辆
   */
  @ResponseBody
  @RequestMapping(value = "getCarByNumberAndFlights", method = RequestMethod.GET)
  public ResultTransport getCarByNumberAndFlights(@RequestParam("carNumber") String carNumber,
	  @RequestParam("flights") String flights,
      @RequestParam("appKey") String appKey) {
    if (StringUtils.isBlank(appKey) || StringUtils.isBlank(carNumber) || StringUtils.isBlank(flights)) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      Car car = carManager.queryCarByNumberAndFlights(carNumber,flights,appKey);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(car);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  
  }
  
  /**
   * 根据类型名称查询车辆类型
   */
  @ResponseBody
  @RequestMapping(value = "getCarTypeByTypeName", method = RequestMethod.GET)
  public ResultTransport getCarTypeByTypeName(@RequestParam("typeName") String typeName,
      @RequestParam("appKey") String appKey) {
    if (StringUtils.isBlank(appKey) || StringUtils.isBlank(typeName)) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      CarType carType = carManager.getCarTypeByTypeName(typeName,appKey);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(carType);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  
  }
  
  /**
   * 专车下单.
   *
   * @param passengerId    乘客id
   * @param passengerPhone 乘客电话
   * @param passengerName  乘客姓名
   * @param userPhone      用车人电话
   * @param companyId      公司id
   * @param companyName    公司名称
   * @param channelName    渠道名称
   * @param serverTime     预约时间
   * @param startAddress   起点
   * @param startLat       起点纬度
   * @param startLng       起点经度
   * @param endAddress     终点
   * @param endLat         终点纬度
   * @param endLng         终点经度
   * @param travelTime     预算时间
   * @param mileage        预算里程
   * @param prePay         是否预付费
   * @param memo           用车需求
   * @param flightNo       航班号
   * @param trainNo        车次号
   * @param operator       操作人
   * @param serviceTypeId  服务类型id
   * @param carTypes       选择车辆
   * @param appKey         区分系统
   */
  @ResponseBody
  @RequestMapping(value = "create", method = RequestMethod.POST)
  public ResultTransport create(
          @RequestParam("passengerId") Long passengerId,
          @RequestParam("passengerPhone") String passengerPhone,
          @RequestParam("passengerName") String passengerName,
          @RequestParam("userPhone") String userPhone,
          @RequestParam("companyId") Long companyId,
          @RequestParam("companyName") String companyName,
          @RequestParam("channelName") String channelName,
          @RequestParam("serverTime") Long serverTime,
          @RequestParam("startAddress") String startAddress,
          @RequestParam("startLat") Double startLat,
          @RequestParam("startLng") Double startLng,
          @RequestParam(required = false, value = "startAddressDetail") String startAddressDetail,
          @RequestParam(required = false, value = "endAddress") String endAddress,
          @RequestParam(required = false, value = "endAddressDetail") String endAddressDetail,
          @RequestParam(required = false, value = "endLat") Double endLat,
          @RequestParam(required = false, value = "endLng") Double endLng,
          @RequestParam(required = false, value = "travelTime") Integer travelTime,
          @RequestParam(required = false, value = "mileage") Double mileage,
          @RequestParam(required = false, value = "prePay") Boolean prePay,
          @RequestParam(required = false, value = "memo") String memo,// 用车需求
          @RequestParam(required = false, value = "flightNo") String flightNo,// 航班号
          @RequestParam(required = false, value = "trainNo") String trainNo,// 车次号
          @RequestParam(required = false, value = "operator") String operator,// 操作人
          @RequestParam(required = false, value = "serviceTypeId") Long serviceTypeId,
          @RequestParam(required = false, value = "serviceType") String serviceType,
          @RequestParam("carTypes") String carTypes,
          @RequestParam(required = false, value = "serverUrl") String serverUrl,// 代驾项目服务器地址
          @RequestParam(required = false, value = "couponIds") String couponIds,// 后台传的参数
          @RequestParam(required = false, value = "couponMoney") Double couponMoney,// 优惠券各车型优惠的总金额
          @RequestParam(required = false, value = "createOrderName") String createOrderName,
          @RequestParam(required = false, value = "useType") String useType, //public:因公用车,private:因私用车
          @RequestParam(required = false, value = "makePrice") BigDecimal makePrice,// 优惠券各车型优惠的总金额
          @RequestParam(required = false, value = "isMakePrice") Integer isMakePrice,
          @RequestParam("appKey") String appKey,
          @RequestParam(required = false, value ="bookStatus") Integer bookStatus,//0否 1是,
          @RequestParam(required = false, value ="book") Integer book,//是否来自于预约用车下单
          @RequestParam(required = false, value ="driverId") Long driverId//指定司机下单
            ) {
    try {
      if (StringUtils.isBlank(appKey)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "系统key不能为空"));
      }

      if (appKey.equals("154fb1999eb7499e8e5696693a416f3f")||appKey.equals("a05a1cf7990b4498a0b9c81b0d47d46c")) { //南航系统
            return ResultTransport.getErrorBy(new Error(-96,
                    "当前APP版本过低，请升级后重试！"));
      }
      if (null == passengerId) {
        return ResultTransport
            .getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(), "客户不存在"));
      }
      if (StringUtils.isBlank(passengerPhone)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "客户姓名不存在"));
      }
      if (StringUtils.isBlank(passengerName)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "客户电话不存在"));
      }
      if (StringUtils.isBlank(userPhone)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "用车人电话不存在"));
      }
      if (null == companyId || companyId == 0) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "公司id不存在"));
      }
      if (StringUtils.isBlank(companyName)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "公司名称不存在"));
      }
      if (StringUtils.isBlank(channelName)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "订单来源不能为空"));
      }
      if (null == serverTime) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "预约时间不能为空"));
      }
      if (StringUtils.isBlank(startAddress)) {
        return ResultTransport
            .getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(), "起点不能为空"));
      }
      if (StringUtils.isBlank(carTypes)) {
        return ResultTransport.getErrorBy(new Error(ErrorConstantV4.PARAM_ERROR.getCode(),
            "车型选择不能为空"));
      }
      List<ServiceEntity> list = JSON.parseArray(carTypes, ServiceEntity.class);
      Double orderPayMoney = 0.0;// 预算总金额
      Integer number = 0;
      for (ServiceEntity serviceEntity : list) {
        orderPayMoney += serviceEntity.getBudgetPay();
        number += serviceEntity.getNumber();// 车型用车数量
      }
      int passengerGender = 0;
      if (channelName.equals(Order.ORDER_TYPE_APP) || channelName.equals(Order.ORDER_TYPE_WEIXIN)
          || channelName.equals(Order.ORDER_TYPE_WEB)) {
        
        if (StringUtils.isNotBlank(serverUrl)) {
          
          Passenger passenger = passengerApi.findById(passengerId, appKey);
          if (null != passenger && "public".equals(useType)) { //因公用车时,客户必须有所属企业,类型为企业用户
            if (null == passenger.getEnterpriseId() || passenger.getType() ==0) {
              return ResultTransport.getErrorBy(ErrorConstantV4.PASSENGER_TYPE_ERROR);
            }
          }
          Long yuyueTimeSetting = daijiaApi.findYuyueTimeSetting(serverUrl); 
          
          //判断是否是预约订单
          if(bookStatus!=null&&bookStatus==1 &&yuyueTimeSetting!=null && yuyueTimeSetting!=0){
        	  if (book!=null&&book == 1) { 
        		  if(serverTime<yuyueTimeSetting+new Date().getTime() &&bookStatus!=null && bookStatus==1){
        			  return ResultTransport.getErrorBy(ErrorConstantV4.YUYUE_TIME_ERROR); 
        		  }
              }
        	  if(serverTime<yuyueTimeSetting+new Date().getTime() &&bookStatus!=null && bookStatus==1){ 
        		  bookStatus=0;
    	  	 } 
            OrderQuery orderQuery = new OrderQuery();
            orderQuery.setPassengerId(passengerId);
            orderQuery.setStatusArray("0,1,2,3,4");
            orderQuery.setAppKey(appKey);
            orderQuery.setBookStatus(bookStatus);
            Long count = orderManager.queryRunOrder(orderQuery);
            if (null != passenger && null != passenger.getPassengerGrade()
                    && passenger.getPassengerGrade().getParallelOrderNumber() > 0
                    && count+number > passenger.getPassengerGrade().getParallelOrderNumber()) {
              String message = "超出最大并行订单数量，不能再下新单。";
              ResultTransport transport = ResultTransport.getErrorBy(new Error(ErrorConstantV4.ZHUAN_ORDER_TOOMACH.getCode(),message));
              Map<String,Object> map = new HashMap<String,Object>();
              map.put("number",count);
              transport.setData(map);
              return transport;
            }
          }else{ 
        	  bookStatus=0;
            OrderQuery orderQuery = new OrderQuery();
            orderQuery.setPassengerId(passengerId);
            orderQuery.setStatusArray("0,1,2,3,4");
            orderQuery.setAppKey(appKey);
            Long count = orderManager.queryRunOrder(orderQuery);
            if (null != passenger && null != passenger.getPassengerGrade()
                    && passenger.getPassengerGrade().getParallelOrderNumber() > 0
                    && count+number > passenger.getPassengerGrade().getParallelOrderNumber()) {
              String message = "超出最大并行订单数量，不能再下新单。";
              ResultTransport transport = ResultTransport.getErrorBy(new Error(ErrorConstantV4.ZHUAN_ORDER_TOOMACH.getCode(),message));
              Map<String,Object> map = new HashMap<String,Object>();
              map.put("number",count);
              transport.setData(map);
              return transport;
            }
          }
          Long num = daijiaApi.countNotPayAmounts(serverUrl, passengerId);
          
          //判断预约时间是否正确
          if(serverTime<yuyueTimeSetting+new Date().getTime() &&bookStatus!=null && bookStatus==1){
            return ResultTransport.getErrorBy(ErrorConstantV4.YUYUE_TIME_ERROR);
          }
          if (!num.equals(0L)) {
            return ResultTransport.getErrorBy(ErrorConstantV4.ORDER_NOTPAY_ERROR);
          }
          
          Long countRunning = orderManager.countRunning(passengerId, appKey);
          if (countRunning >= 10) {
            return ResultTransport.getErrorBy(ErrorConstantV4.ORDER_RUNNING_ERROR);
          }
          
        }
      }
      
      if (StringUtils.isNotBlank(serverUrl)) {
        prePay = daijiaApi.findErrandSetting(serverUrl);
      }
      
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      Date serverDate = new Date(serverTime);
      
      if (!channelName.equals(Order.ORDER_TYPE_PHONE) && (number <= 0 || number > 10)) {
        return ResultTransport.getErrorBy(
            new Error(ErrorConstantV4.PARAM_ERROR.getCode(), "选择车辆数量错误"));
      }
      if (null == couponMoney) {
        couponMoney = 0.0;
      }
      if(null!=driverId){
          channelName=Order.ORDER_TYPE_SCAN;
      }
      if (null != prePay && prePay && !channelName.equals(Order.ORDER_TYPE_PHONE)
          && (orderPayMoney - couponMoney >= 0)) { // 需要预付费,下单到orderTemp表
        instance =
            orderTempManager.createV4up(passengerId, passengerName, passengerPhone, userPhone,
                companyId, companyName, channelName, serverDate, startAddress, startLat, startLng,
                endAddress, endLat, endLng, true, travelTime, mileage, memo, flightNo, trainNo,
                operator, serviceTypeId,serviceType, carTypes, serverUrl, couponMoney,
                createOrderName, appKey,bookStatus,isMakePrice,makePrice);
      } else { // 不需要预付费 直接下单
        instance =
            orderManager.createV4up(passengerId, passengerName, passengerPhone, userPhone,passengerGender,
                companyId, companyName, channelName, serverDate, startAddress, startAddressDetail,
                startLat, startLng, endAddress, endAddressDetail, endLat, endLng, false,
                travelTime, mileage, memo, flightNo, trainNo, operator, serviceTypeId, serviceType,
                carTypes, couponIds, serverUrl, couponMoney, createOrderName, useType, appKey,
                    bookStatus,makePrice,isMakePrice,driverId);
      }
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  
  }

  /**
   * 司机补单.
   */
  @ResponseBody
  @RequestMapping(value = "createmore", method = RequestMethod.POST)
  public ResultTransport createMore(@RequestParam("passengerId") Long passengerId,
      @RequestParam("passengerName") String passengerName,
      @RequestParam("passengerPhone") String passengerPhone,
      @RequestParam("companyId") Long companyId,
      @RequestParam("companyName") String companyName,
      @RequestParam("serverTime") Long serverTime,
      @RequestParam("startAddress") String startAddress,
      @RequestParam("startLat") Double startLat,
      @RequestParam("startLng") Double startLng,
      @RequestParam(required = false, value = "endAddress") String endAddress,
      @RequestParam(required = false, value = "endLat") Double endLat,
      @RequestParam(required = false, value = "endLng") Double endLng,
      @RequestParam("areaId") Long areaId,
      @RequestParam("employId") Long employId,
      @RequestParam("serviceTypeId") Long serviceTypeId,
      @RequestParam("employName") String employName,// 服务人员名称
      @RequestParam("employPhone") String employPhone,// 服务人员电话
      @RequestParam(required = false, value = "employPhoto") String employPhoto,// 服务人员头像地址
      @RequestParam(required = false, value = "employNo") String employNo,// 服务人员工号
      @RequestParam(required = false, value = "flightNo") String flightNo,// 航班号
      @RequestParam(required = false, value = "trainNo") String trainNo,// 车次号
      @RequestParam(required = false, value = "budgetPay") Double budgetPay,
      @RequestParam(required = false, value = "travelTime") Integer travelTime,
      @RequestParam(required = false, value = "mileage") Double mileage,
      @RequestParam(required = false, value = "preStartPrice") Double prestartPrice,
      @RequestParam(required = false, value = "preMileagePrice") Double premileagePrice,
      @RequestParam(required = false, value = "preRunTimePrice") Double prerunTimePrice,
      @RequestParam(required = false, value = "inBlackList") Boolean inBlackList,
      @RequestParam(required = false, value = "rentalCompanyId") Long rentalCompanyId,
      @RequestParam(required = false, value = "rentalCompanyName") String rentalCompanyName,
      @RequestParam(required = false, value = "serverUrl") String serverUrl,// 代驾项目服务器地址
      @RequestParam(required = false, value = "voiceId") Long voiceId,// 语音消息id
      @RequestParam(required = false, value = "voiceHttpPath") String voiceHttpPath,// 语音消息路径
      @RequestParam("appKey") String appKey) {
    try {
        if (appKey.equals("154fb1999eb7499e8e5696693a416f3f")||appKey.equals("a05a1cf7990b4498a0b9c81b0d47d46c")) { //南航的系统
            return ResultTransport.getErrorBy(new Error(-96,
                    "当前APP版本过低，请升级后重试！"));
        }
      if (StringUtils.isNotBlank(serverUrl)) {
        if (null != voiceId) { //语音消息检查是否是新消息
          ResultTransport transport = daijiaApi.queryVoiceState(serverUrl, voiceId);
          if (transport.getCode()==0) {
            if (Integer.valueOf(transport.getData().toString())!=1) { //不是已派单不能补单
              return ResultTransport.getErrorBy(ErrorConstantV4.VOICE_STATUS_ERROR);
            }
          }
        }
        //进行司机状态判断
        try {
          Map<String, Object> map = daijiaApi.queryDriver(serverUrl, employId);
          //status
          if (null != map && (Integer)map.get("status")!=1) {
            return  ResultTransport.getErrorBy(ErrorConstantV4.ORDER_NOTPAY_ERROR);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        
        try {
          Map<String, Object> map = daijiaApi.queryCountRunning(serverUrl, passengerId);
          if (null != map && (Integer)map.get("code")!=0) {
            return  ResultTransport.getErrorBy(ErrorConstantV4.ZHUAN_ORDER_TOOMACH);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      OrderQuery orderQuery = new OrderQuery();
      orderQuery.setEmployId(employId);
      orderQuery.setStatusArray("1,2,3,4");
      orderQuery.setAppKey(appKey);
      orderQuery.setTreatment(false);
      orderQuery.setBookStatus(0);
      Long count = orderManager.countByParam(orderQuery);
      if (count > 0) {
        return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_STATUS_ERROR);
      }
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance =
          orderManager.createMoreV4up(passengerId, passengerName, passengerPhone, companyId,
              companyName, Order.ORDER_TYPE_BUDAN, new Date(serverTime), startAddress, startLat,
              startLng, endAddress, endLat, endLng, travelTime, mileage, areaId, employId,
              employName, employPhone, employPhoto, employNo, serviceTypeId, flightNo, trainNo,
              budgetPay, prestartPrice, premileagePrice, prerunTimePrice, inBlackList,
              rentalCompanyId,rentalCompanyName, serverUrl, appKey,voiceId, voiceHttpPath);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 转换临时订单数据到真实订单.
   *
   * @param orderId 临时订单id
   * @param prePayTypeDetail 预支付方式
   * @param appKey 系统key
   */

  @ResponseBody
  @RequestMapping(value = "tempToForever", method = RequestMethod.GET)
  public ResultTransport tempToForever(@RequestParam("orderId") Long orderId,
      @RequestParam("prePayTypeDetail") String prePayTypeDetail,
      @RequestParam("appKey") String appKey) {
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      OrderTemp temp = orderTempManager.findByIdAndAppKey(orderId, appKey);
      Order order = null;
      // 没有处理过的临时订单,把临时订单放到真实订单里
      if (!temp.getTreatment()) {
        Double shouldPay = 0.0;
        if (temp.getBudgetPay() != null) {
          if (temp.getCouponMoney() != null) {
            shouldPay = temp.getBudgetPay() - temp.getCouponMoney();
          } else {
            shouldPay = temp.getBudgetPay();
          }
        }
        order =
            orderManager.tempToForeverV4up(prePayTypeDetail, temp.getCompanyId(),
                temp.getCompanyName(), temp.getPassengerId(), temp.getPassengerName(),
                temp.getPassengerPhone(), temp.getShowPhone(), temp.getCarTypeId(),
                temp.getChannelName(), temp.getStartAddress(), temp.getStartAddressDetail(),
                temp.getStartLat(), temp.getStartLng(), temp.getEndAddress(),
                temp.getEndAddressDetail(), temp.getEndLat(), temp.getEndLng(),
                temp.getServerTime(), temp.getStartPrice(), temp.getMileagePrice(),
                temp.getRunTimePrice(), temp.getBudgetPay(), temp.getCouponId(),
                temp.getEmployId(), shouldPay, temp.getRunTime(), temp.getMileage(),
                temp.getMemo(), temp.getFlightNo(), temp.getTrainNo(), temp.getServiceTypeId(),
                temp.getAreaId(), temp.getServerUrl(), appKey);

        orderTempManager.update(orderId, appKey);
      }
      
      Passenger passenger = passengerApi.findById(temp.getPassengerId(), appKey);
      
      String areaName = "";
      if(null!=temp.getServerUrl() && null!=temp.getAreaId()){
        areaName = daijiaApi.findAreaName(temp.getServerUrl(), temp.getAreaId());
      }
      
      dockingSuperviseApi.pushDdjsMessage(order, temp.getPassengerPhone(), passenger.getGender(), temp.getServerTime(),
    		  temp.getStartAddress(), temp.getStartLat(), temp.getStartLng(), 
    		  temp.getServiceType().toString(), temp.getEndAddress(), temp.getEndLat(), temp.getEndLng(), 
    		  temp.getAreaId(), areaName, temp.getMemo());
      
      
      instance.setData(order);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 根据分组Id查询一组临时订单.
   */

  @ResponseBody
  @RequestMapping(value = "queryByGroupId", method = RequestMethod.GET)
  public ResultTransport queryByGroupId(@RequestParam("groupId") Long groupId,
      @RequestParam("appKey") String appKey) {
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      List<OrderTemp> list = orderTempManager.queryByGroupId(groupId, appKey);
      instance.setData(list);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 查询一组真实订单.
   *
   * @param groupId 分组id
   */

  @ResponseBody
  @RequestMapping(value = "findByGroupId", method = RequestMethod.GET)
  public ResultTransport findByGroupId(@RequestParam("groupId") Long groupId,
      @RequestParam("appKey") String appKey) {
    try {
      OrderQuery orderQuery = new OrderQuery();
      orderQuery.setGroupId(groupId);
      orderQuery.setAppKey(appKey);
      List<Order> list = orderManager.queryByGroupId(orderQuery);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(list);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * APP多条件查询订单.
   */

  @ResponseBody
  @RequestMapping(value = {"", "/"}, method = RequestMethod.GET)
  public ResultTransport findByParams(
      @RequestParam(required = false, value = "companyId") Long companyId, 
      @RequestParam(required = false, value = "companyName") String companyName, 
      @RequestParam(required = false, value = "orderNo") String orderNo,
      @RequestParam(required = false, value = "employId") Long employId,
      @RequestParam(required = false, value = "employName") String employName, 
      @RequestParam(required = false, value = "employPhone") String employPhone, 
      @RequestParam(required = false, value = "passengerId") Long passengerId,
      @RequestParam(required = false, value = "passengerName") String passengerName, 
      @RequestParam(required = false, value = "passengerPhone") String passengerPhone,
      @RequestParam(required = false, value = "carNumber") String carNumber,
      @RequestParam(required = false, value = "status") String status,
      @RequestParam(required = false, value = "allorderType") String allorderType,
      @RequestParam(required = false, value = "allstatus") String allstatus,
      @RequestParam(required = false, value = "orderby") String orderby,
      @RequestParam(required = false, value = "page") Integer page,
      @RequestParam(required = false, value = "rows") Integer rows,
      @RequestParam(required = false, value = "startTime") Long startTime, 
      @RequestParam(required = false, value = "endTime") Long endTime,
      @RequestParam(required = false, value = "treatment") Boolean treatment,
      @RequestParam(required = false, value = "startFinishTime") Long startFinishTime, 
      @RequestParam(required = false, value = "endFinishTime") Long endFinishTime, 
      @RequestParam(required = false, value = "createOrderName") String createOrderName, 
      @RequestParam("appKey") String appKey) {
    try {
      OrderQuery orderQuery = new OrderQuery();
      orderQuery.setCompanyId(companyId);
      orderQuery.setCompanyName(companyName);
      orderQuery.setOrderNo(orderNo);
      orderQuery.setEmployId(employId);
      orderQuery.setEmployNameOrPhone(employName);
      orderQuery.setEmployPhone(employPhone);
      orderQuery.setPassengerId(passengerId);
      orderQuery.setPassengerNameOrPhone(passengerName);
      orderQuery.setPassengerPhone(passengerPhone);
      orderQuery.setCarNumber(carNumber);
      orderQuery.setChannelNameArray(allorderType);
      orderQuery.setOrderby(orderby);
      orderQuery.setPage(page);
      orderQuery.setRows(rows);
      orderQuery.setStartTime(startTime);
      orderQuery.setEndTime(endTime);
      orderQuery.setStatusArray(status);
      orderQuery.setStatusArray(allstatus);
      orderQuery.setStartFinishTime(startFinishTime);
      orderQuery.setEndFinishTime(endFinishTime);
      orderQuery.setCreateOrderName(createOrderName);
      orderQuery.setAppKey(appKey);
      if (treatment != null && treatment) { // 选中"未支付选项"时,查询已确认费用的订单
        if (StringUtils.isBlank(allstatus)) {
          orderQuery.setStatusArray("4");
          orderQuery.setTreatment(treatment);
        }
      }

      DataGrid<Order> dataGrid = orderManager.findByParams(orderQuery);

      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(dataGrid);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 导出订单查询数据接口.
   */

  @ResponseBody
  @RequestMapping(value = {"exportOrders"}, method = RequestMethod.GET)
  public ResultTransport exportOrders(
      @RequestParam(required = false, value = "companyId") Long companyId,
      @RequestParam(required = false, value = "companyName") String companyName,
      @RequestParam(required = false, value = "orderNo") String orderNo,
      @RequestParam(required = false, value = "employName") String employName,
      @RequestParam(required = false, value = "employPhone") String employPhone,
      @RequestParam(required = false, value = "passengerName") String passengerName,
      @RequestParam(required = false, value = "passengerPhone") String passengerPhone, 
      @RequestParam(required = false, value = "carNumber") String carNumber,
      @RequestParam(required = false, value = "status") String status,
      @RequestParam(required = false, value = "allorderType") String allorderType,
      @RequestParam(required = false, value = "allstatus") String allstatus,
      @RequestParam(required = false, value = "orderby") String orderby,
      @RequestParam(required = false, value = "page") Integer page,
      @RequestParam(required = false, value = "rows") Integer rows,
      @RequestParam(required = false, value = "startTime") Long startTime,
      @RequestParam(required = false, value = "endTime") Long endTime,
      @RequestParam(required = false, value = "treatment") Boolean treatment,
      @RequestParam(required = false, value = "startFinishTime") Long startFinishTime,
      @RequestParam(required = false, value = "endFinishTime") Long endFinishTime,
      @RequestParam(required = false, value = "createOrderName") String createOrderName,
      @RequestParam("appKey") String appKey) {
    try {
      OrderQuery orderQuery = new OrderQuery();
      orderQuery.setCompanyId(companyId);
      orderQuery.setCompanyName(companyName);
      orderQuery.setOrderNo(orderNo);
      orderQuery.setEmployNameOrPhone(employName);
      orderQuery.setEmployPhone(employPhone);
      orderQuery.setPassengerNameOrPhone(passengerName);
      orderQuery.setPassengerPhone(passengerPhone);
      orderQuery.setCarNumber(carNumber);
      orderQuery.setChannelNameArray(allorderType);
      orderQuery.setOrderby(orderby);
      orderQuery.setPage(page);
      orderQuery.setRows(rows);
      orderQuery.setStartTime(startTime);
      orderQuery.setEndTime(endTime);
      orderQuery.setStatusArray(status);
      orderQuery.setStatusArray(allstatus);
      orderQuery.setStartFinishTime(startFinishTime);
      orderQuery.setEndFinishTime(endFinishTime);
      orderQuery.setCreateOrderName(createOrderName);
      orderQuery.setAppKey(appKey);
      if (treatment != null && treatment) { // 选中"未支付选项"时,查询已确认费用的订单
        if (StringUtils.isBlank(allstatus)) {
          orderQuery.setStatusArray("4");
          orderQuery.setTreatment(treatment);
        }
      }

      DataGrid<Order> dataGrid = orderManager.exportOrders(orderQuery);

      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(dataGrid);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * 后台查询单个订单.
   *
   * @param id 订单id
   * @return 订单完整信息
   */

  @ResponseBody
  @RequestMapping(value = "findByOrderId", method = RequestMethod.GET)
  public ResultTransport findByOrderId(@RequestParam("orderId") Long id,
      @RequestParam("appKey") String appKey) {
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      Order order = orderManager.findByIdAndAppKey(id, appKey);
      instance.setData(order);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * APP查询客户的未销单的所有订单.
   *
   * @param passengerId 客户id
   * @param page 分页
   * @param rows 每页条数
   * @param status 状态
   */

  @ResponseBody
  @RequestMapping(value = "findOrdersV4up", method = RequestMethod.GET)
  public ResultTransport findOrdersV4up(Long passengerId, Integer page, Integer rows,
      String status, String appKey) {
    try {
      OrderQuery orderQuery = new OrderQuery();
      orderQuery.setPassengerId(passengerId);
      orderQuery.setPage(page);
      orderQuery.setRows(rows);
      orderQuery.setStatusArray(status);
      orderQuery.setOrderby("status asc,review asc,finishTime desc,serverTime desc");
      orderQuery.setAppKey(appKey);

      DataGrid<Map<String, Object>> dataGrid = orderManager.findOrdersV4up(orderQuery);
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(dataGrid);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }
  
  /**
   * APP查询客户的未销单的所有订单.(三级等保)
   *
   * @param passengerId 客户id
   * @param page 分页
   * @param rows 每页条数
   * @param status 状态
   */

  @ResponseBody
  @RequestMapping(value = "findOrdersV4upSjdb", method = RequestMethod.GET)
  public ResultTransport findOrdersV4upSjdb(Long passengerId, Integer page, Integer rows,
      String status, String appKey) {
    try {
      OrderQuery orderQuery = new OrderQuery();
      orderQuery.setPassengerId(passengerId);
      orderQuery.setPage(page);
      orderQuery.setRows(rows);
      orderQuery.setStatusArray(status);
      orderQuery.setOrderby("status asc,review asc,finishTime desc,serverTime asc");
      orderQuery.setAppKey(appKey);

      DataGrid<Map<String, Object>> dataGrid = orderManager.findOrdersV4up(orderQuery);
      
      List<Map<String, Object>> mapList = dataGrid.getRows();
      if(!CollectionUtils.isEmpty(mapList)){
    	  for (Map<String, Object> map : mapList) {
    	      map.put("passengerPhone", AesUtil.aesEncrypt(map.get("passengerPhone").toString(), AesUtil.VIPARA));
    	      if(null!=map.get("userPhone")){
    	    	  map.put("userPhone", AesUtil.aesEncrypt(map.get("userPhone").toString(), AesUtil.VIPARA));
    	      }
    	      map.put("startAddress", AesUtil.aesEncrypt(map.get("startAddress").toString(), AesUtil.VIPARA));
    	      if(null!=map.get("startAddressDetail")){
    	    	  map.put("startAddressDetail", AesUtil.aesEncrypt(map.get("startAddressDetail").toString(), AesUtil.VIPARA));
    	      }
    	      map.put("startLat", AesUtil.aesEncrypt(map.get("startLat").toString(), AesUtil.VIPARA));
    	      map.put("startLng", AesUtil.aesEncrypt(map.get("startLng").toString(), AesUtil.VIPARA));
    	      if(null!=map.get("endAddress")){
    	    	  map.put("endAddress", AesUtil.aesEncrypt(map.get("endAddress").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("endAddressDetail")){
    	    	  map.put("endAddressDetail", AesUtil.aesEncrypt(map.get("endAddressDetail").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("endLat")){
    	    	  map.put("endLat", AesUtil.aesEncrypt(map.get("endLat").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("endLng")){
    	    	  map.put("endLng", AesUtil.aesEncrypt(map.get("endLng").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("budgetPay")){
    	    	  map.put("budgetPay", AesUtil.aesEncrypt(map.get("budgetPay").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("startPrice")){
    	    	  map.put("startPrice", AesUtil.aesEncrypt(map.get("startPrice").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("mileagePrice")){
    	    	  map.put("mileagePrice", AesUtil.aesEncrypt(map.get("mileagePrice").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("runTimePrice")){
    	    	  map.put("runTimePrice", AesUtil.aesEncrypt(map.get("runTimePrice").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("realPay")){
    	    	  map.put("realPay", AesUtil.aesEncrypt(map.get("realPay").toString(), AesUtil.VIPARA));
    	      }
    	      map.put("companyName", AesUtil.aesEncrypt(map.get("companyName").toString(), AesUtil.VIPARA));
    	      if(null!=map.get("employName")){
    	    	  map.put("employName", AesUtil.aesEncrypt(map.get("employName").toString(), AesUtil.VIPARA));// 昵称
    	      }
    	      if(null!=map.get("employPhone")){
    	    	  map.put("employPhone", AesUtil.aesEncrypt(map.get("employPhone").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("employNo")){
    	    	  map.put("employNo", AesUtil.aesEncrypt(map.get("employNo").toString(), AesUtil.VIPARA));// 工号
    	      }
    	      if(null!=map.get("employPhoto")){
    	    	  map.put("employPhoto", AesUtil.aesEncrypt(map.get("employPhoto").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("carNumber")){
    	    	  map.put("carNumber", AesUtil.aesEncrypt(map.get("carNumber").toString(), AesUtil.VIPARA));
    	      }
    	      if(null!=map.get("carName")){
    	    	  map.put("carName", AesUtil.aesEncrypt(map.get("carName").toString(), AesUtil.VIPARA));
    	      }
    	  }
      }
      dataGrid.setRows(mapList);
      
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      instance.setData(dataGrid);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * APP查询单个订单(司机端).
   *
   * @param id 订单id
   * @param serverUrl 代驾项目服务器地址
   * @return 订单
   */

  @ResponseBody
  @RequestMapping(value = "findByOrderIdV4up", method = RequestMethod.GET)
  public ResultTransport findByOrderIdV4up(
      @RequestParam("orderId") Long id,
      @RequestParam(required = false, value = "serverUrl") String serverUrl,
      @RequestParam("appKey") String appKey) {
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      Map<String, Object> map = orderManager.findByIdAndAppKeyV4up(id, appKey);
      try {
        if (StringUtils.isNotBlank(serverUrl)) {
          Object object = map.get("areaId");
          List<ChargeStartTime> chargeStartTimes =
              daijiaApi.findChargeStartTimes(serverUrl, Long.valueOf(object.toString()));
          map.put("chargeStartTimes", chargeStartTimes);
        }
      } catch (Exception ex) {
        map.put("chargeStartTimes", null);
      }

      instance.setData(map);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }

  /**
   * APP查询单个订单(客户端).
   */

  @ResponseBody
  @RequestMapping(value = "findOneV4up", method = RequestMethod.GET)
  public ResultTransport findOneV4up(@RequestParam("orderId") Long id,
      @RequestParam("appKey") String appKey) {
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      Map<String, Object> map = orderManager.findOneV4up(id, appKey);
      instance.setData(map);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }
  
  /**
   * APP查询单个订单(客户端)(三级等保).
   */

  @ResponseBody
  @RequestMapping(value = "findOneV4upSjdb", method = RequestMethod.GET)
  public ResultTransport findOneV4upSjdb(@RequestParam("orderId") Long id,
      @RequestParam("appKey") String appKey) {
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      Map<String, Object> map = orderManager.findOneV4up(id, appKey);
      
      map.put("passengerPhone", AesUtil.aesEncrypt(map.get("passengerPhone").toString(), AesUtil.VIPARA));
      if(null!=map.get("userPhone")){
    	  map.put("userPhone", AesUtil.aesEncrypt(map.get("userPhone").toString(), AesUtil.VIPARA));
      }
      map.put("startAddress", AesUtil.aesEncrypt(map.get("startAddress").toString(), AesUtil.VIPARA));
      if(null!=map.get("startAddressDetail")){
    	  map.put("startAddressDetail", AesUtil.aesEncrypt(map.get("startAddressDetail").toString(), AesUtil.VIPARA));
      }
      map.put("startLat", AesUtil.aesEncrypt(map.get("startLat").toString(), AesUtil.VIPARA));
      map.put("startLng", AesUtil.aesEncrypt(map.get("startLng").toString(), AesUtil.VIPARA));
      if(null!=map.get("endAddress")){
    	  map.put("endAddress", AesUtil.aesEncrypt(map.get("endAddress").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("endAddressDetail")){
    	  map.put("endAddressDetail", AesUtil.aesEncrypt(map.get("endAddressDetail").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("endLat")){
    	  map.put("endLat", AesUtil.aesEncrypt(map.get("endLat").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("endLng")){
    	  map.put("endLng", AesUtil.aesEncrypt(map.get("endLng").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("budgetPay")){
    	  map.put("budgetPay", AesUtil.aesEncrypt(map.get("budgetPay").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("startPrice")){
    	  map.put("startPrice", AesUtil.aesEncrypt(map.get("startPrice").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("mileagePrice")){
    	  map.put("mileagePrice", AesUtil.aesEncrypt(map.get("mileagePrice").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("runTimePrice")){
    	  map.put("runTimePrice", AesUtil.aesEncrypt(map.get("runTimePrice").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("realPay")){
    	  map.put("realPay", AesUtil.aesEncrypt(map.get("realPay").toString(), AesUtil.VIPARA));
      }
      map.put("companyName", AesUtil.aesEncrypt(map.get("companyName").toString(), AesUtil.VIPARA));
      if(null!=map.get("employName")){
    	  map.put("employName", AesUtil.aesEncrypt(map.get("employName").toString(), AesUtil.VIPARA));// 昵称
      }
      if(null!=map.get("employPhone")){
    	  map.put("employPhone", AesUtil.aesEncrypt(map.get("employPhone").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("employNo")){
    	  map.put("employNo", AesUtil.aesEncrypt(map.get("employNo").toString(), AesUtil.VIPARA));// 工号
      }
      if(null!=map.get("employPhoto")){
    	  map.put("employPhoto", AesUtil.aesEncrypt(map.get("employPhoto").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("carNumber")){
    	  map.put("carNumber", AesUtil.aesEncrypt(map.get("carNumber").toString(), AesUtil.VIPARA));
      }
      if(null!=map.get("carName")){
    	  map.put("carName", AesUtil.aesEncrypt(map.get("carName").toString(), AesUtil.VIPARA));
      }
      
      instance.setData(map);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }
  
  /**
   * 统计客户的订单数量.(0,1,2,3,4)
   */
  
  @ResponseBody
  @RequestMapping(value = "countRunOrder", method = RequestMethod.GET)
  public ResultTransport countRunOrder(
      @RequestParam("passengerId") Long passengerId,
      @RequestParam("appKey") String appKey) {
    if (passengerId == null || StringUtils.isBlank(appKey)) {
      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
    }
    try {
      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      OrderQuery orderQuery = new OrderQuery();
      
      orderQuery.setPassengerId(passengerId);
      orderQuery.setStatusArray("0,1,2,3,4");
      orderQuery.setAppKey(appKey);
      Long total = orderManager.queryRunOrder(orderQuery);
      
      instance.setData(total);
      return instance;
    } catch (Exception ex) {
      ex.printStackTrace();
      return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
  }
  @RequestMapping("findCarTypeRelByCarTypeId")
  @ResponseBody
  public ResultTransport findCarTypeRelByCarTypeId(@RequestParam("carTypeId")Long carTypeId,
		  @RequestParam(required = true, value = "appKey") String appKey){
	  if (null == carTypeId || StringUtils.isBlank(appKey)) {
	      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
	    }
	    try {
	    	CarTypeQuery carTypeQuery = new CarTypeQuery();
	    	carTypeQuery.setAppKey(appKey);
	    	carTypeQuery.setCarTypeId(carTypeId);
	      List<CarTypeRel> list = carTypeManager.findByCarTypeRelBycarTypeId(carTypeId, appKey);
	      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
	      instance.setData(list);
	      return instance;
		} catch (Exception e) {
			e.printStackTrace();
		}
	    return null;
  }
  
  @RequestMapping("getCarTypeByIftaxi")
  @ResponseBody
  public ResultTransport getCarTypeByIftaxi(@RequestParam("ifTaxi")String ifTaxi,
		  @RequestParam(required = true, value = "appKey") String appKey){
	  if (null == ifTaxi || StringUtils.isBlank(appKey)) {
	      return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
	    }
	    try {
	      List<CarType> list = carTypeManager.getCarTypeByIftaxi(ifTaxi, appKey);
	      ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
	      instance.setData(list);
	      return instance;
		} catch (Exception e) {
			e.printStackTrace();
		}
	    return null;
  }
}
